$(function(){
 provinceList("provinceId");
})
function addUser()
{
   var email=$("#email").val();
   var password=$("#password").val();
   var repassword=$("#repassword").val();
   var provinceId=$("#provinceId").val();
   var cityId=$("#cityId").val();
   var username=$("#username").val();
   var postCode=$("#postCode").val();
   var tel=$("#tel").val();
   var sex=$("input[type='radio']:checked").val();
   $("#email,#password,#repassword").css({"border": ""});
   var reg= /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
	  if(email=="")
	  {
	     $("#email").css({"border": "2px solid red"});
	     alert("请输入邮箱地址!");
	     return false;
	  }else if(!reg.test(email))
	  {
	   
	    $("#email").css({"border": "2px solid red"});
		alert("邮箱格式不对!");
		return false;
	  }
	  if(password.length<5||password.length>30)
	  {
	    alert("密码的长度在5~30之间!");
	    return false;
	  }else if(password!=repassword)
	  {
	     alert("两次输入密码不一致！");
	     return false;
	  }
	  if(provinceId==""||provinceId=="-1"||cityId==""||cityId=="-1")
	  {
	    alert("请选择所在城市!");
	    return false;
	  }
	  
   var param={"user.email":email,"user.password":password,"user.provinceId":provinceId,"user.cityId":cityId,"user.username":encodeURI(username),"user.postCode":postCode,"user.tel":tel,"user.sex":sex,"user.level":0};
   $.getJSON("user!addUser.action",param,function(data){
       if(data.info=="have")
       {
           alert("邮箱已经被注册,请用其它的!");
       }
       else if(data.info)
       {
          alert("注册成功!");
		  window.location.href=location.href.replace("register.jsp",'login.jsp');
       }else
       {
          alert("注册失败");
       }
   });
}